<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Review extends MY_Luckydog
{
    public function __construct()
    {
        parent::__construct();
        $login_status = $this->login_status = $this->check_login_status();
        if (empty($login_status)){
            redirect('/luckydog/login');
        }
        $this->load->model('luckydog/Review_model', 'review');
    }
    public function index()
    {
        $_SESSION['v_menu'] =  'review';
        $starttime = $this->input->get("starttime",true)?$this->input->get("starttime",true):"";
        $endtime = $this->input->get("endtime",true)?$this->input->get("endtime",true):"";
        $content = $this->input->get("content",true)?$this->input->get("content",true):"";
        $newsid = $this->input->get("newsid",true)?$this->input->get("newsid",true):"";
        $status = $this->input->get("status");
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        
        $filter = array(
            'starttime'=>strtotime($starttime),
            'endtime'=>strtotime($endtime),
            'content'=>$content,
            'status'=>$status,
            'newsid'=>$newsid
        );

        $limit = 20;
        $total_rows = $this->review->get_review_cnt($filter);
        $filter_url = "";
        if($newsid)
        {
            $filter_url .= "&newsid=".$newsid;
        }
        if($status !== '')
        {
            $filter_url .= "&status=".$status;
        }
        if($content)
        {
            $filter_url .= "&content=".$content;
        }
        $base_url = '/luckydog/review/index?'.$filter_url;
        $page_links = $this->create_page_links($base_url,$total_rows,$limit);
        $reviewList = $this->review->reviewList($filter,$per_page,$limit);
        $data = array(
            'reviewList'=>$reviewList,
            'page_links'=>$page_links,
            'per_page'=>$per_page,
            'total_rows'=>$total_rows,
            'status'=>$status
        );
        $this->load->view("/luckydog/review/list",$data);
    }
    //编辑状态信息
    public function edit_status(){
        $status = $this->input->post("status",true)?$this->input->post("status",true):"";
        $id = $this->input->post("id",true)?$this->input->post("id",true):"";
        $res = $this->review->edit_status($id,$status);
        if($res)
        {
            //更新评论数+1
            $reviewInfo = $this->review->getReviewInfoByID($id);
            if($reviewInfo)
            {
                $this->review->updateReviewCnt($reviewInfo['newsID']);    
            }
            
        }
        echo $res;
    }


}
/* End of file index.php */
/* Location: ./application/controllers/luckydog/index.php */